home *** CD-ROM | disk | FTP | other *** search
/ Apple WWDC 1996 / WWDC96_1996 (CD).toast / Technology Materials / MacApp Release 10 / MacApp Release 10 - HD Ready / Libraries / Core / Includes / UObject.h < prev    next >
Encoding:
Text File  |  1996-04-03  |  9.5 KB  |  283 lines  |  [TEXT/MPS ]

  1. // UObject.h
  2. // Copyright © 1984-96 by Apple Computer, Inc. All rights reserved.
  3.  
  4. #ifndef __UOBJECT__
  5. #define __UOBJECT__
  6.  
  7. // MacApp
  8.  
  9. #ifndef __MACAPPTYPES__
  10. #include "MacAppTypes.h"
  11. #endif
  12.  
  13. #ifndef __UCLASSDESC__
  14. #include "UClassDesc.h"
  15. #endif
  16.  
  17. #ifndef __UPOINTEROBJECT__
  18. #include "UPointerObject.h"
  19. #endif
  20.  
  21. // ANSI
  22.  
  23.  
  24. //----------------------------------------------------------------------------------------
  25. // Forward and external class declarations.
  26. //----------------------------------------------------------------------------------------
  27.  
  28. class TObject;
  29. class TStream;
  30. class TDependencySpace;
  31.  
  32. //----------------------------------------------------------------------------------------
  33. // Typedefs
  34. //----------------------------------------------------------------------------------------
  35.  
  36. enum ComparisonResult
  37. {
  38.     kLessThan = -1,
  39.     kEqual = 0,
  40.     kGreaterThan = 1
  41. };
  42.  
  43. typedef long HashValue;
  44.  
  45. //----------------------------------------------------------------------------------------
  46. // TObject: Definition of the system's root object
  47. //----------------------------------------------------------------------------------------
  48.  
  49. #if    (qDebug || qSym) && defined(__MWERKS__)
  50.     #define qForceClassIDFirstHack    1
  51.     
  52.     // make sure CodeWarrior puts fClassID first, not the vtable
  53.     struct ForceClassIDFirst
  54.     {
  55.         ClassID fClassID;
  56.     };
  57. #else
  58.     #define qForceClassIDFirstHack    0
  59. #endif
  60.  
  61. #if    qForceClassIDFirstHack
  62. class TObject : public ForceClassIDFirst
  63. #else
  64. class TObject
  65. #endif
  66. {
  67.     MA_DECLARE_CLASS;
  68.     
  69. public:
  70.  
  71. #if (qDebug || qSym) && !qForceClassIDFirstHack
  72.     ClassID fClassID;                // Used to do object validation in debug mode.
  73. #endif
  74.  
  75.     //------------------------------------------------------------------------------------
  76.     // Constructor, destructor, Initializer and I<Method>.
  77.     //------------------------------------------------------------------------------------
  78.  
  79. #if qInspector
  80.     TObject();
  81. #else
  82.     inline TObject()
  83.     { }
  84. #endif
  85.         // Constructor
  86.         
  87.     virtual ~TObject();
  88.         // Destructor
  89.     
  90. #if qDebug || qSym || qInspector || qTheDebugger
  91.     void IObject();
  92. #else
  93.     inline void IObject()
  94.     { }
  95. #endif
  96.         // The ancestral initializer. Should be called in the I<ClassName> chain. i.e.
  97.         // IView -> IEventHandler -> IObject, followed by a called to <ClassName> i.e without
  98.         // the T.
  99.  
  100.     //------------------------------------------------------------------------------------
  101.     // Allocate and deallocate.
  102.     //------------------------------------------------------------------------------------
  103.  
  104.     inline void* operator new(size_t size)
  105.        { return MAOperatorNew(size); }
  106.  
  107.     void operator delete(void* obj);
  108.  
  109.     virtual TObject* Clone();
  110.         // Makes a duplicate copy of this. The default calls this->ShallowClone, which
  111.         // makes a literal copy of instance variables but does not attempt to clone owned
  112.         // objects. A subclass which owns other objects should override this to clone the
  113.         // owned objects and data structures as well.
  114.  
  115.     virtual void Free();
  116.         // Called to dispose of an object. Gives object a chance to cleanup after itself.
  117.         // Default simply calls this->ShallowFree, which makes no attempt to free instance
  118.         // variables. Should be overridden by any class which allocates space or owns
  119.         // other objects in its instance variables.. Be sure to call Inherited!
  120.  
  121.     //------------------------------------------------------------------------------------
  122.     // Comparison
  123.     //------------------------------------------------------------------------------------
  124.     
  125.     HashValue Hash() const;
  126.  
  127.     inline Boolean IsSame(const TObject* theObject) const
  128.     { return this == theObject; }
  129.         // Does a handle comparison to determine if the objects are in fact the same object
  130.     
  131.     virtual Boolean IsEqual(const TObject* theObject) const;
  132.         // Must be overridden to be useful.  Default implementation calls IsSame
  133.     
  134.     virtual ComparisonResult CompareObject(const TObject* theObject) const;
  135.         // Compares two objects.
  136.         
  137.     virtual Boolean IsGreaterThan(const TObject* obj) const;
  138.     
  139.     virtual Boolean IsLessThan(const TObject* obj) const;
  140.     
  141.     inline Boolean operator<(const TObject& obj) const
  142.     { return  (this->IsLessThan(&obj)); }
  143.         // Calls back to IsLessThan.
  144.     
  145.     inline Boolean operator>(const TObject& obj) const
  146.     { return (this->IsGreaterThan(&obj)); }
  147.         // Calls back to IsGreaterThan.
  148.     
  149.     inline Boolean operator>=(const TObject& obj) const
  150.     { return (this->IsGreaterThan(&obj) || this->IsEqual(&obj)); }
  151.         // Calls back to IsGreaterThan and IsEqual.
  152.     
  153.     inline Boolean operator<=(const TObject& obj) const
  154.     { return (this->IsLessThan(&obj) || this->IsEqual(&obj)); }
  155.         // Calls back to IsLessThan and IsEqual.
  156.     
  157.     inline Boolean operator ==(const TObject& obj) const
  158.     { return (this->IsEqual(&obj)); }
  159.         // Calls back to IsEqual.
  160.         
  161.     inline Boolean operator !=(const TObject& obj) const
  162.     { return (this->IsEqual(&obj) == FALSE); }
  163.     
  164.     //------------------------------------------------------------------------------------
  165.     // Change notification //••• SRF this could be removed to a mixin
  166.     //------------------------------------------------------------------------------------
  167.  
  168.     void AddDependent(TObject* dependent);
  169.         // Registers the specified object as a dependent of this object in the global
  170.         // dependency space "gMacAppDependencies", so that it will be notified of changes 
  171.         // in this object.
  172.  
  173.     void RemoveDependent(TObject* dependent);
  174.         // Remove the specified object from the list of dependents of this object in 
  175.         // the global dependency space "gMacAppDependencies".
  176.  
  177.     virtual void Changed(ChangeID theChange, TObject* changedBy);
  178.         // Called to inform dependents of this object in the global dependency space 
  179.         // "gMacAppDependencies" that it has been changed. 
  180.         // "theChange" will often contain a command number.
  181.         // "changedBy" will often contain a command object. 
  182.         // Called often, overridden rarely.
  183.  
  184.     virtual void DoUpdate(ChangeID theChange, 
  185.                                 TObject* changedObject,
  186.                                 TObject* changedBy,
  187.                                 TDependencySpace* dependencySpace);
  188.         // Informs this object that an object on which it is dependent in the global
  189.         // dependency space "gMacAppDependencies" has been changed.
  190.         // Called rarely, overridden often.
  191.  
  192.     virtual TDependencySpace* GetDependencySpace();
  193.         // Returns the default dependency space for storing dependents of this object.
  194.         // Returns gMacAppDependencies.
  195.  
  196.     virtual void SetMark(Boolean state);
  197.         // Intended to mark (state=true) or unmark (state=false) this object. Can be used
  198.         // by dependency spaces that require marking, and overridden by objects that store the
  199.         // mark internally. The MacApp dependency spaces do not use this method. 
  200.  
  201.     virtual Boolean IsMarked();
  202.         // Intended to return true if this object is marked. Can be used
  203.         // by dependency spaces that require marking, and overridden by objects that store the
  204.         // mark internally. The MacApp dependency spaces do not use this method. 
  205.  
  206.     virtual void RemoveAllDependencies();
  207.         // Used by TObject::Free to remove all dependency relations in the global
  208.         // dependency space "gMacAppDependencies" which involve this object, either 
  209.         // as notifier or as dependent.
  210.         
  211.     virtual Boolean RemoveDependenciesOnFree();
  212.         // Default is to return true. This will allow us to optimize certain system
  213.         // objects (like TToolBoxEvents).
  214.  
  215.  
  216.  
  217.     //------------------------------------------------------------------------------------
  218.     // Standard signature support.
  219.     //------------------------------------------------------------------------------------
  220.  
  221.     virtual IDType GetStandardSignature();    // override 
  222.         // Returns this class's standard signature.
  223.  
  224.     //------------------------------------------------------------------------------------
  225.     // Stream I/O protocol support. 
  226.     //------------------------------------------------------------------------------------
  227.  
  228.     virtual void ReadFrom(TStream* aStream);
  229.     
  230.     virtual void WriteTo(TStream* aStream);
  231.  
  232.  
  233.     //------------------------------------------------------------------------------------
  234.     // Miscellaneous protocol and support methods.
  235.     //------------------------------------------------------------------------------------
  236.  
  237.     inline ClassID GetClassID() const
  238.     { return (GetClassDescDynamic())->GetClassID(); }
  239.         // Returns the class ID of this.
  240.  
  241.     inline void GetClassName(ClassName& clName) const
  242.     { (GetClassDescDynamic())->GetClassName(clName); }
  243.         // Returns the class name of this.
  244.  
  245.     inline const char* GetClassName() const
  246.     { return (GetClassDescDynamic())->GetClassName(); }
  247.         // Returns a pointer to the class name of this.
  248.  
  249.     inline size_t GetClassSize() const
  250.     { return (GetClassDescDynamic())->GetClassSize(); }
  251.         // Returns the basic instantiation size. i.e. the size in bytes of a newly created
  252.         // object of this class.
  253.  
  254.     inline const ClassDesc* GetSuperClass() const
  255.     { return (GetClassDescDynamic())->GetBaseClass(); }
  256.         // Returns ClassDesc for the immediate superclass. Returns NULL for TObject. If we
  257.         // ever get MI this will have to be an enumerator.
  258.  
  259.     inline Boolean DescendsFrom(const ClassDesc* classDesc) const
  260.     { return (GetClassDescDynamic())->DescendsFrom(classDesc); }
  261.         // True if my class is a subclass of the class described by ClassDesc.
  262.         
  263.     inline Boolean IsSameClass(const ClassDesc* classDesc) const
  264.     { return GetClassDescDynamic() == classDesc; }
  265.         // True if my class is the same as the class described by ClassDesc.
  266.  
  267. #if qDebugMsg
  268.     void SubClassResponsibility();
  269. #else
  270.     inline void SubClassResponsibility()
  271.     { }
  272. #endif
  273.         // Called from methods that MUST be overridden in a subclass. Signals failure.
  274. };
  275.  
  276.  
  277. typedef TObject* TObjectPtr;
  278. typedef TObjectPtr* TObjectPtrPtr;
  279. typedef TObjectPtrPtr* TObjectPtrHandle;
  280.  
  281.  
  282. #endif
  283.